<!-- 编辑新增对话框js,如有需要请导出到对应的对话框js文件中 -->
var userListDialog = function(){
    var modal = $('#userListDialog');
    var _roleId;
    var btnRemove = modal.find("#btnRemove");

    btnRemove.click(function(){
        var selections = modal.find("#userListTable").bootstrapTable('getSelections');
        if (selections) {
            var pkArray = [];
            for(var i in selections){
                pkArray.push(selections[i].uuid);
            }
            $.ajax({
                url: _CTX_ + "/core/role/removeRByUserIds",
                type: 'POST',
                data: $.param({"userIds": pkArray, "roleId": _roleId}, true),
                cache: false,
                dataType: 'json',
                success: function (ret) {
                    if (ret.state == 'ok') {
                        alert("移除成功");
                        modal.find("#userListTable").bootstrapTable('refresh');
                    } else {
                        alert(ret.msg);
                    }
                }
            });
        }
    });

    var _datasetKit = _GetDatasetKit("OrgList");

    modal.find("#userListTable").bootstrapTable({
        url: _CTX_ + "/core/account/getByRoleIdNoCache",
        method: 'get',
        queryParams: function () {
            //每次查询时传入后台的查询条件
            return _roleId?{"roleId": _roleId}:null;
        },
        height: 360,
        pagination: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [20, 50, 100],
        toolbar: "#userListDialogToolbar",
        clickToSelect: true,
        search: true,
        searchOnEnterKey: true,
        showRefresh: true,
        columns: [{
            checkbox: true
        }, {
            field: 'uuid',
            title: '主键',
            visible: false,
            searchable: false
        }, {
            field: 'name',
            title: '姓名'
        }, {
            field: 'phone',
            title: '电话号码'
        }, {
            field: 'email',
            title: '邮箱地址'
        }, {
            field: 'orgnazation',
            title: '所属部门',
            formatter: function (value, row, index, field) {
                return _datasetKit.getLabel("OrgList", value);
            }
        }]
    });


    return {
        show: function (entity, options) {
            if(options && options.title){
                modal.find(".modal-title").html(options.title);
            }
            if(entity && entity.roleId){
                _roleId = entity.roleId;
                modal.find("#userListTable").bootstrapTable("refresh");
                modal.modal('show');
            }else{
                alert("无法获取角色信息,请重试");
            }

        }
    }

}();